/*******************************************************************************
 * Copyright (c) 2014 Steffen Mikkelsen
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Steffen Mikkelsen - initial API and implementation
 ******************************************************************************/
package com.subsecret.secureconnection.securestream.stream.monitor;

import java.io.IOException;
import java.io.OutputStream;

import com.subsecret.secureconnection.securestream.stream.AbstractOutputStreamWrapper;

public class MonitorableOutputStream extends AbstractOutputStreamWrapper {
    
    private long transferred = 0;
    private long totalTransferred = 0;
    
    public MonitorableOutputStream(OutputStream os) {
        super(os);
    }
    
    public long getBytesTransferred() {
        return transferred;
    }
    
    public long getBytesTransferredTotal() {
        return totalTransferred;
    }
    
    public void resetBytesTransferred() {
        transferred = 0;
    }
    
    @Override
    public void write(int b) throws IOException {
        os.write(b);
        transferred++;
        totalTransferred++;
    }
    
    @Override
    public void write(byte b[]) throws IOException {
        os.write(b);
        transferred += b.length;
        totalTransferred += b.length;
    }
    
    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        os.write(b, off, len);
        transferred += len;
        totalTransferred += len;
    }
    
}
